package top.lanscarlos.ashcraft.service;

import com.sun.istack.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import top.lanscarlos.ashcraft.pojo.Commodity;
import top.lanscarlos.ashcraft.pojo.Seller;
import top.lanscarlos.ashcraft.repository.CommodityRepository;
import top.lanscarlos.ashcraft.repository.SellerRepository;

import java.util.List;

/**
 * Ashcraft
 * top.lanscarlos.ashcraft.service
 *
 * @author Lanscarlos
 * @since 2022-05-26 20:55
 */
@Service
public class CommodityService {
    @Autowired
    private CommodityRepository repository;

    public List<Commodity> query(@Nullable String name, int sellerId) {
        return repository.query(name, sellerId);
    }

    @Nullable
    public Commodity create(
            int sellerId,
            @NotNull String name,
            @NotNull String description,
            @NotNull String image,
            @NotNull double price,
            @NotNull int storage,
            @NotNull String category
    ) {
        Commodity commodity = new Commodity(name, description, image, price, storage, category);
        return repository.insert(sellerId, commodity) ? commodity : null;
    }
}
